package com.example.snackfood.services.impl;

import com.example.snackfood.dao.SnackFoodPaymentsDao;
import com.example.snackfood.entity.Carts;
import com.example.snackfood.entity.Payments;
import com.example.snackfood.services.IsnackFoodPaymentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Service;

/**
 * @program: snackFood
 * @description:
 * @author: lydms
 * @create: 2023-11-24 22:50
 **/


@Service
public class SnackFoodPaymentsService implements IsnackFoodPaymentsService {

    @Autowired
    private SnackFoodPaymentsDao snackFoodPaymentsDao;

    @Override
    public void savePayments(Payments payments) {
        snackFoodPaymentsDao.save(payments);
    }

    @Override
    public void deletePayments(Long id) {
        Query query=new Query(Criteria.where("id").is(id));
        snackFoodPaymentsDao.delete(query);
    }

    public void updatePayments(Payments payments) {
        Query query=new Query(Criteria.where("id").is(payments.getId()));
        Update update=new Update();

        update.set("order_id",payments.getOrder_id());
        update.set("payment_method",payments.getPayment_method());
        update.set("transaction_id",payments.getTransaction_id());
        update.set("amount",payments.getAmount());
        update.set("status",payments.getStatus());
        snackFoodPaymentsDao.update(query,update);
    }


    public Payments getPayments(Payments payments) {
        Criteria criteriaid=Criteria.where("id").is(payments.getId());
        Criteria orCriteria = new Criteria();
        orCriteria.orOperator(criteriaid);
        Query query=new Query(orCriteria);
        return  snackFoodPaymentsDao.get(query);
    }
}
